#include "server.h"
    
char * ReFile(char* Filename)   //删除文件或目录
{
    struct dirent* pdirent;     
    struct stat st;
    int ret = 0;
    char *cwd = getcwd(NULL,0); //获取当前路径
    DIR* pdir = opendir(cwd);       //打开当前目录
    if(NULL == pdir){             
        perror("no such file or directory");
        return "cannot find such file or directory";
    }
    while((pdirent = readdir(pdir)) != NULL){    //迭代读取目录内容
        stat(pdirent->d_name,&st);            
        if(S_ISDIR(st.st_mode) && strcmp(pdirent->d_name,Filename) == 0)
        {     //目标文件为文件夹
            ret = rmdir(pdirent->d_name);   //删除文件夹
            ERROR_CHECK(ret,-1,"rmdir");
            return "remove success";
        }
        else if(S_ISREG(st.st_mode) && strcmp(pdirent->d_name,Filename) == 0){ //目标文件为文件
            ret =  unlink(pdirent->d_name);  //删除文件
            ERROR_CHECK(ret,-1,"unlink");
            return "remove success";
        }
        else if(strcmp(pdirent->d_name,Filename)){   //文件不存在
            return "cannot find this file";
        }
    }
}
